package com.lsz.deport.ui.order;

import androidx.annotation.NonNull;

import com.common.config.MyApi;
import com.common.retrofit.RxObserver;
import com.common.retrofit.json.Data;
import com.lsz.deport.json.OrderBean;
import com.lsz.deport.json.OrderDetailBean;
import com.lsz.deport.json.VIPMemberBean;
import com.util_code.base.mvp.RxMvpPresenter;
import com.util_code.utils.RxUtils;
import com.util_code.utils.ToastUtils;

import java.util.List;

import javax.inject.Inject;

import okhttp3.RequestBody;

public class OrderPresent extends RxMvpPresenter<OrderView> {

    protected MyApi mMyApi;

    @Inject
    public OrderPresent(MyApi myApi) {
        this.mMyApi = myApi;
    }

    public void getOrderDetail(String id) {
        mMyApi.getOrderDetail(id)
                .compose(RxUtils.<Data<List<OrderDetailBean>>>applySchedulersLifeCycle(getView()))
                .subscribe(new RxObserver<Data<List<OrderDetailBean>>>() {

                    @Override
                    public void onNext(@NonNull Data<List<OrderDetailBean>> data) {
                        if (checkJsonCode(data, true)) {
                            getView().onSuccess(data.data);
                        } else {
                            getView().onFail();
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        getView().onFail();
                    }
                });
    }
}
